str1 = input().split()
tre = ''
prosto = 0
zifra = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}
for i in range(3):
    if len(str1) == 3 and str1[i] in zifra:
        tre += str(zifra[str1[i]])
    else:
        print('Wrong answer')
        break
if len(tre) == 3:
    tre = int(tre)
    plus = tre
    mines = tre
    f = 0
    d = 0
    while prosto == 0:
        for j in range(2, plus):
            if plus % j == 0:
                d += 1
        for k in range(2, mines):
            if mines % k == 0:
                f += 1
        if d == 0 and f == 0:
            if tre - mines == plus - tre or tre - mines < plus - tre:
                prosto = mines
                break
            elif tre - mines > plus - tre:
                prosto = plus
                break
        elif f == 0:
            prosto = mines
            break
        elif d == 0:
            prosto = plus
            break
        else:
            mines -= 1
            plus += 1
            f = 0
            d = 0
    print(prosto)
